package it.azienda.framework.utilita;

import org.apache.commons.beanutils.Converter;
import org.apache.commons.beanutils.converters.*;
import java.util.StringTokenizer;

public class CurrencyConverter implements Converter{
    private DoubleConverter doubleConverter = new DoubleConverter();
    /** Creates a new instance of CurrencyConverter */
    public CurrencyConverter() {
        
    }
    public Object convert(Class type, Object value) 
{ 
    if(value == null || value.toString().length() < 1) 
        return null; 
    String valore = (String)value;
    if(valore.indexOf(',')!=-1||valore.indexOf('.')!=-1){
        StringTokenizer st = new StringTokenizer(valore.replace('.', ' '));  
        valore = "";
        while(st.hasMoreTokens())  
            valore=valore+(st.nextToken());
    }
        value = valore.replace(',','.');

    return doubleConverter.convert(type, value); 
    }
    
}
